package Offer;

/**
 * @author lakersUp
 * @Classname       lastRemaining
 * @Description     圆圈中最后剩下的数字
 *              死亡循环杀:
 *                  动态规划转移方程 : f(x)=(f(x-1)+m)%x;
 * @Date 2022/2/28 15:07
 * @Version 1.0
 */
public class Offer62lastRemaining {
    public int lastRemaining(int n, int m) {
        int res=0;
        for(int i=2;i<=n;i++){
            res=(res+m)%i;
        }
        return res;
    }
}
